<div ng-controller="Report_PurchaseC">
    <div class="bg-light lter b-b wrapper-md">
        <h1 class="m-n font-thin h3">采购明细报表</h1>
    </div>
    <div class="wrapper-md" style="text-align: center;">
        <div class="panel panel-default">
            <div class="panel-heading">
                <div class="col-lg-3 col-md-3 col-sm-3 col-xs-12" style="float: right">
                    <a class="btn btn-sm btn-default" ng-href="../api/Report/ExpPurchaseReport?createTime={{newdate.format('yyyy-MM-dd')}}&name={{finddata}}">
                        <i class="fa fa-cloud-download text"></i>
                        <span class="text">全部导出</span>
                    </a>
                </div>
                <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 input-group">
                    <input type="text" class="form-control" placeholder="请输入" ng-model="finddata">
                    <span class="input-group-btn">
                        <!--<button class="btn btn-default" type="button" ng-click="find()">查找</button>-->
                    </span>
                    <input type="date" class="form-control" placeholder="查询日期" ng-model="newdate">
                    <span class="input-group-btn">
                        <button class="btn btn-default" type="button" ng-click="find()">查找</button>
                    </span>
                </div>
            </div>
            <div class="table-responsive">
                <table id="example1" class="table table-striped b-t b-light table-bordered">
                    <thead>
                    <tr>
                        <th style="text-align: center;" ng-repeat="item in neworders[0] track by $index">{{item}}</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr ng-repeat="ord in orders track by $index">
                        <td class="text-center" ng-repeat="item in ord track by $index">{{item}}</td>
                    </tr>
                    </tbody>
                </table>
                <!--<div class="panel-heading" ng-include="'/htm/tpl/Supplier/Paging.html'"></div>-->
                <div class="panel-heading" my-pagination get-page-data="getData" mypagedata="pageData"></div>
            </div>
        </div>
    </div>
</div>

<script>
    Date.prototype.format = function (format) {
        var o = {
            "M+": this.getMonth() + 1, //month  
            "d+": this.getDate(), //day  
            "h+": this.getHours(), //hour  
            "m+": this.getMinutes(), //minute  
            "s+": this.getSeconds(), //second  
            "q+": Math.floor((this.getMonth() + 3) / 3), //quarter  
            "S": this.getMilliseconds() //millisecond  
        }
        if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
        (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o) if (new RegExp("(" + k + ")").test(format))
            format = format.replace(RegExp.$1,
            RegExp.$1.length == 1 ? o[k] :
            ("00" + o[k]).substr(("" + o[k]).length));
        return format;
    }
    angular.module('app')
        .controller("Report_PurchaseC", function ($scope, $state, $http) {
            $scope.pageData = {};
            $scope.pageData.Page = 0;
            $scope.finddata = "";
            $scope.newdate = "";
            $scope.pageData.Rows = $scope.defPageRows;
            $scope.getData = function (p, r) {
                if (p) {
                    p = p < 1 ? 1 : p;
                } else p = 1;
                if (r) {
                } else r = $scope.defPageRows;
//                    $http({
//                        url: "../api/Report/PurchaseReport?page=" + p + "&rows=" + r + "&createTime=" + $scope.newdate + "&name=" + $scope.finddata,
//                        method: "GET"
//                    })
//                            .then(function (res) {
                $http.get("../api/Report/PurchaseReport", { params: { page: p, rows: r, createTime: $scope.newdate, name: $scope.finddata } })
                    .then(function (res) {
                        console.log(res);
                        $scope.orders = res.data.Data;
                        $scope.neworders = $scope.orders.splice(0,1);
                        $scope.pageData = res.data;
                    })
                    .then(function (error) {
                        if (error) {
                            alert("数据获取失败");
                        }
                    });
            };
            $scope.find = function () {
                console.log($scope.newdate);
                $scope.getData(1, $scope.pageData.Rows);
            };
            //加载数据
            $scope.getData(1, $scope.pageData.Rows);
        })
</script>